<?php defined('BASE_PATH') or die('No direct script access.');
/*
 * File : controller.php
 * Type : Class controller
 * Module : login
 * Date : 26/11/2010
*/
Class loginController extends Controller {
    private $data = array();
    public function index() {
        if($this->session->admin!=NULL){
           redirect(BASE_URL.ADMIN_URL);
        }
        $this->load->model('login/Mlogin');
        if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateForm()) {
            if($this->Mlogin->check($this->request->post)){
                $this->session->admin='ok';
                redirect(ADMIN_URL);
            }else {
                $this->data['error'][]='Tên đăng nhập hoặc mật khẩu không chính xác.';
            }
        }
        $this->template->write('title', 'Login to admin');
        /** Nạp template ***/
        // loop over the array object and echo variables and values
        $this->template->view('left','login','admin/index',$this->data);
        #render để hoàn tất load template
        $this->template->render();
    }
    private function validateForm(){
        $this->load->library('validate');
        $this->validate
                ->rule('user',$this->request->post['user'],'user is not empty','not_empty')
                ->rule('user',$this->request->post['user'],'Email ko chính xác','email')
                ->rule('pass',$this->request->post['pass'],'Password is not empty','not_empty')
                ->check();
        if($this->validate->_errors==NULL){
            return TRUE;
        }else {
            $this->data['error']=$this->validate->_errors;
        }

    }
    function upload(){
        echo $aaa='aaa';
    }
}
// end of file index controller
